let packages = ops::get_resolved_packages(&resolve, registry);
let profiles = try!(ws.current()).manifest().profiles();
+ let host_triple = try!(opts.config.rustc_info()).host.clone();
let mut cx = try!(Context::new(ws, &resolve, &packages, opts.config,
BuildConfig {
- host_triple: opts.config.rustc_info().host.clone(),
+ host_triple: host_triple,
requested_target: opts.target.map(|s| s.to_owned()),
release: opts.release,
..BuildConfig::default()
let cfg_target = try!(config.get_string("build.target")).map(|s| s.val);
let target = target.or(cfg_target);
let mut base = ops::BuildConfig {
- host_triple: config.rustc_info().host.clone(),
+ host_triple: try!(config.rustc_info()).host.clone(),
requested_target: target.clone(),
jobs: jobs,
..Default::default()
try!(cx.rustflags_args(unit))
};
let fingerprint = Arc::new(Fingerprint {
- rustc: util::hash_u64(&cx.config.rustc_info().verbose_version),
+ rustc: util::hash_u64(&try!(cx.config.rustc_info()).verbose_version),
target: util::hash_u64(&unit.target),
profile: util::hash_u64(&unit.profile),
features: format!("{:?}", features),
let name = unit.pkg.name().to_string();
if !cx.show_warnings(unit.pkg.package_id()) {
- if cx.config.rustc_info().cap_lints {
+ if try!(cx.config.rustc_info()).cap_lints {
rustc.arg("--cap-lints").arg("allow");
} else {
rustc.arg("-Awarnings");
// We don't build/rust doctests if target != host
if let Some(target) = options.compile_opts.target {
- if config.rustc_info().host != target {
+ if try!(config.rustc_info()).host != target {
return Ok(errors);
}
}
pub struct Config {
home_path: Filesystem,
shell: RefCell<MultiShell>,
- rustc_info: Rustc,
+ rustc_info: RefCell<Option<Rustc>>,
values: RefCell<HashMap<String, ConfigValue>>,
values_loaded: Cell<bool>,
cwd: PathBuf,
let mut cfg = Config {
home_path: Filesystem::new(homedir),
shell: RefCell::new(shell),
- rustc_info: Rustc::blank(),
+ rustc_info: RefCell::new(None),
cwd: cwd,
values: RefCell::new(HashMap::new()),
values_loaded: Cell::new(false),
};
try!(cfg.scrape_tool_config());
- try!(cfg.scrape_rustc_version());
try!(cfg.scrape_target_dir_config());
Ok(cfg)
pub fn rustdoc(&self) -> &Path { &self.rustdoc }
- pub fn rustc_info(&self) -> &Rustc { &self.rustc_info }
+ pub fn rustc_info(&self) -> CargoResult<Ref<Rustc>> {
+ if self.rustc_info.borrow().is_none() {
+ *self.rustc_info.borrow_mut() = Some(try!(Rustc::new(&self.rustc)));
+ }
+ Ok(Ref::map(self.rustc_info.borrow(), |opt| opt.as_ref().unwrap()))
+ }
pub fn values(&self) -> CargoResult<Ref<HashMap<String, ConfigValue>>> {
if !self.values_loaded.get() {
Ok(())
}
- fn scrape_rustc_version(&mut self) -> CargoResult<()> {
- self.rustc_info = try!(Rustc::new(&self.rustc));
- Ok(())
- }
-
fn scrape_target_dir_config(&mut self) -> CargoResult<()> {
if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
*self.target_dir.borrow_mut() = Some(Filesystem::new(self.cwd.join(dir)));
usage, &args, false);
assert_eq!(result.unwrap(), Some("foo <version>".to_string()));
}
+
+#[test]
+fn version_works_without_rustc() {
+ let p = project("foo");
+ assert_that(p.cargo_process("version").env("PATH", ""),
+ execs().with_status(0));
+}
\ No newline at end of file